package luogu.dfs;
//P1451 求细胞数量与岛屿数量一致

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/21 21:15
 */
public class CellCount {
    static int n,m;
    static int count=0;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        sc.nextLine();
        boolean[][]st=new boolean[n][m];
        char[][]chars=new char[n][];
        for (int i = 0; i < n; i++) {
            chars[i]=sc.nextLine().toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(chars[i][j]!='0'){
                    dfs(chars,i,j);
                    count++;
                }
            }
        }
        System.out.println(count);

    }
    public static void dfs(char[][] chars,int x,int y){
        if(chars[x][y]=='0'){
            return ;
        }
        int[]dx={-1,1,0,0};
        int[]dy={0,0,1,-1};
        chars[x][y]='0';
        for (int i = 0; i < 4; i++) {
            int a=x+dx[i],b=y+dy[i];
            if(a>=0&&b>=0&&a<n&&b<m){
                dfs(chars,a,b);
            }
        }

    }
}
